package cn.demo.common.core.domain.entity;

import com.mybatisflex.annotation.Column;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.core.constant.SqlOperator;
import com.mybatisflex.core.query.SqlOperators;
import cn.demo.common.mybatisFlex.MyInsertListener;
import cn.demo.common.mybatisFlex.MyUpdateListener;
import cn.demo.common.annotation.Excel;
import io.swagger.v3.oas.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cn.demo.common.core.domain.BaseEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 部门对象 sys_dept
 *
 * @author xtjun
 * @date 2024-06-05
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Table(value = "sys_dept",onInsert = MyInsertListener.class,onUpdate = MyUpdateListener.class)
public class SysDept extends BaseEntity {
    private static final long serialVersionUID = 1L;

    @Id
    @Schema(description = "部门id")
    private String deptId;

    @Excel(name = "父部门id")
    @Schema(description = "父部门id")
    private String parentId;

    @Excel(name = "祖级列表")
    @Schema(description = "祖级列表")
    private String ancestors;

    @NotBlank(message = "部门名称不能为空")
    @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
    @Excel(name = "部门名称")
    @Schema(description = "部门名称")
    private String deptName;

    @NotNull(message = "显示顺序不能为空")
    @Excel(name = "显示顺序")
    @Schema(description = "显示顺序")
    private Long orderNum;

    @Excel(name = "负责人")
    @Schema(description = "负责人")
    private String leader;

    @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
    @Excel(name = "联系电话")
    @Schema(description = "联系电话")
    private String phone;

    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    @Excel(name = "邮箱")
    @Schema(description = "邮箱")
    private String email;

    @Excel(name = "纬度")
    @Schema(description = "纬度")
    private String lat;

    @Excel(name = "经度")
    @Schema(description = "经度")
    private String lng;

    @Excel(name = "部门状态", dictType = "sys_data_status")
    @Schema(description = "部门状态(字典:sys_data_status)")
    private Integer status;

    @Schema(description = "删除标志(字典:sys_del_status)")
    private Integer delFlag;

    /**
     * 父部门名称
     */
    @Column(ignore = true)
    private String parentName;

    /**
     * 子部门
     */
    private List<SysDept> children = new ArrayList<>();

    // 自定义字段的 SQL 操作符
    @JsonIgnore
    public static final SqlOperators operators = new SqlOperators() {{
        set(SysDept::getParentId, SqlOperator.EQUALS);
        set(SysDept::getAncestors, SqlOperator.LIKE);
        set(SysDept::getDeptName, SqlOperator.LIKE);
        set(SysDept::getOrderNum, SqlOperator.EQUALS);
        set(SysDept::getLeader, SqlOperator.EQUALS);
        set(SysDept::getPhone, SqlOperator.EQUALS);
        set(SysDept::getEmail, SqlOperator.EQUALS);
        set(SysDept::getLat, SqlOperator.EQUALS);
        set(SysDept::getLng, SqlOperator.EQUALS);
        set(SysDept::getStatus, SqlOperator.EQUALS);
    }};
}
